import QtQuick 1.1

Rectangle {
    width: 866
    height: 616
    color: "transparent"

    signal makeClonezillaDevice (int index, string disk, string label)

    function onDoingPercent(index, percent)
    {
        console.log("index:" + index +"percent:" + percent)
        //usbModle.setProperty(index, usbPerVal, percent);
        console.log("Hello: " +usbModle.get(0).usbPerVal);
        usbModle.get(index).usbPerVal = percent;
        console.log("Hello: " +usbModle.get(0).usbPerVal);
        usbModle.sync();

    }

    function onUsbDiskInserted(disk, label, volume, fileSystem)
    {
        for (var i=0; i<usbModle.count; i++)
        {
            if (disk == usbModle.get(i).usbDisk)
            {
                return;
            }
        }
        console.log("Insert device label:" + label)
        usbModle.append({usbDiskIcon: "images/usbDisk.png",
                            usbDiskLable: label,
                            usbDisk: disk,
                            usbVolume: volume,
                            usbFileSystem: fileSystem,
                            usbPerVal: 0});
    }

    function onUsbDiskRemoved(disk)
    {
        console.log("Removed disk: " + disk + "\n")
        for (var i=0; i<usbModle.count; i++)
        {
            if (disk == usbModle.get(i).usbDisk)
            {
                usbModle.remove(i);
            }
        }
    }

    Image {
        id: bkgTop
        fillMode: Image.PreserveAspectFit
        source: "images/bkg.png"
    }
    Image {
        id: btnClose
        x: parent.width - 55
        y: 25
        z: 1
        source: "images/btn-close.png"
        MouseArea {
            anchors.fill: parent
            onClicked: {
                Qt.quit();
            }
        }
    }
    Image {
        id: btnMinium
        x: btnClose.x - 10 - width
        y: btnClose.y
        z: 1
        source: "images/btn-mini.png"
        MouseArea {
            anchors.fill: parent
            onClicked: {
                mainWindow.showMinimized();
            }
        }
    }

    MouseArea {
        id: dragRegion
        x: 0; y: 0
        width: parent.width
        height: 160
        property variant clickPos: "0,0"
        onPressed: {
            clickPos  = Qt.point(mouse.x,mouse.y)
        }
        onPositionChanged: {
            //鼠标偏移量
            var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
            mainWindow.pos = Qt.point(mainWindow.x+delta.x, mainWindow.y+delta.y);
        }
    }
/*
    Rectangle {
        id: bkgBottom
    }
*/
    ListModel {
        id: usbModle
        /*
        ListElement {
            usbDiskIcon: "images/usbDisk.png"
            usbDiskLable: "Kinston2"
            usbDisk: "E:"
            usbVolume: "4G"
            usbFileSystem: "fat"
        }
        */
    }

    Component {
        id: highlight
        Rectangle {
            x: 10
            width: usbDiskList.width - 20; height: usbDiskList.listItemHeight - 2 + 10
            color: "lightsteelblue"; radius: 5
            y: usbDiskList.currentItem.y - 10
            Behavior on y {
                SpringAnimation {
                    spring: 3
                    damping: 0.2
                }
            }
        }
    }

    //Component {
    //    id: usbListHeader
        Rectangle {
                width: usbDiskList.width - 10
                height: 55
                x: 30
                y: 160
                color: "transparent"

                Text {
                    id: iconSection
                    anchors.verticalCenter: parent.verticalCenter
                    width: 80
                    font { pixelSize: 24  }
                    color: "white"
                    text: "Icon"
                }
                Text {
                    id: driSection
                    anchors.verticalCenter: parent.verticalCenter
                    width: 85
                    anchors.left: iconSection.right
                    font { pixelSize: 24  }
                    color: "white"
                    text: "Drive"
                }
                Text {
                    id: labelSection
                    anchors.verticalCenter: parent.verticalCenter
                    width: 100
                    anchors.left: driSection.right
                    font { pixelSize: 24  }
                    color: "white"
                    text: "Label"
                }
                Text {
                    id: volumeSection
                    anchors.verticalCenter: parent.verticalCenter
                    width: 100
                    anchors.left: labelSection.right
                    font { pixelSize: 24  }
                    color: "white"
                    text: "Volume"
                }
                Text {
                    id: fileSystemSection
                    anchors.verticalCenter: parent.verticalCenter
                    width: 170
                    anchors.left:  volumeSection.right
                    font { pixelSize: 24  }
                    color: "white"
                    text: "FileSystem"
                }
                Text {
                    id: procSection
                    anchors.verticalCenter: parent.verticalCenter
                    width: 170
                    anchors.left: fileSystemSection.right
                    font { pixelSize: 24  }
                    color: "white"
                    text: "Process"
                }
                Text {
                    width: 95
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: procSection.right
                    font { pixelSize: 24  }
                    color: "white"
                    text: "Operation"
                }
        }
    //}

    ListView {
        id: usbDiskList

        property int listItemHeight: 55

        x: 0; y: 225; width: parent.width-x; height: parent.height - y - 50
        clip: true
        highlight: highlight
        highlightFollowsCurrentItem: false
        focus: true
        spacing: 10
        model: usbModle
        //header: usbListHeader
        delegate: UsbDelegate{width: usbDiskList.width; height: usbDiskList.listItemHeight}
    }


}
